import 'package:flutter/material.dart';
import 'package:dio/dio.dart';



class HttpDioDemo extends StatefulWidget{

@override
  State<StatefulWidget> createState() {

    return HttpDioDemoState();
  }
}


class HttpDioDemoState extends State<HttpDioDemo>{

  Dio _dio = Dio();

  @override
  Widget build(BuildContext context) {

    return Scaffold(

      appBar: AppBar(title: Text('HttpDioDemo'),),

      body: Container(
        alignment: Alignment.center,
        child: FutureBuilder(
            future: _dio.get("https://www.baidu.com"),
            builder: (BuildContext context, AsyncSnapshot snapshot) {
              //请求完成
              if (snapshot.connectionState == ConnectionState.done) {
                Response response = snapshot.data;
                //发生错误
                if (snapshot.hasError) {
                  return Text(snapshot.error.toString());
                }

                return Text(response.data);
              }
              //请求未完成时弹出loading
              return CircularProgressIndicator();
            }
        ),
      )
    );
  }
}